package com.example.demo.util;

import com.example.demo.domain.User;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @program: demo
 * @description: 从token中解析用户名
 * @author: wangze
 * @create: 2020-09-11 16:13
 **/
public class ParseUsername {
    public static String getUsername(){
        User user=(User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return user.getUsername();
    }
    public static User getUser(){
        User user=(User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return user;
    }
}
